﻿using SecsaMvcApplication.Controllers;
using SecsaMvcApplication.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace SecsaMvcApplication.Filters
{
    public class AuthSessionFilter : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var usuarioSession = HttpContext.Current.Session["LoggedIn"];
            
            if (usuarioSession == null && !(filterContext.Controller is AccountController))
            {
                RouteValueDictionary route = new RouteValueDictionary();
                route.Add("Action", "Login");
                route.Add("Controller", "Account");

                //filterContext.Result = new RedirectToRouteResult(route);
            }

            base.OnActionExecuting(filterContext);
        }
    }
}